package org.drools.devguide;

import org.drools.devguide.eshop.model.Item;
import org.kie.api.KieServices;
import org.kie.api.runtime.KieContainer;
import org.kie.api.runtime.KieSession;
import org.kie.api.runtime.rule.FactHandle;

/**
 * Hello world!
 *
 */
public class App 
{
    public static void main( String[] args )
    {
        System.out.println("启动规则引擎...");
        KieServices kieServices=KieServices.Factory.get();
        KieContainer kieContainer=kieServices.getKieClasspathContainer();
        KieSession kieSession=kieContainer.newKieSession();
        Item item=new Item("A",123.0,234.0);
        System.out.println("Item Category:"+item.getCategory());
        FactHandle factHandle=kieSession.insert(item);
        int fired=kieSession.fireAllRules();
        System.out.println("Number of Rules executed="+fired);
        System.out.println("Item Category:"+item.getCategory());
        System.out.println("update Item cost to 230.0");
        item.setCost(230.0);
        kieSession.update(factHandle,item);
        kieSession.fireAllRules();
        System.out.println("Item Category:"+item.getCategory());

    }
}
